# try-except
# try
#       检测范围
# except[expression [as identifier]]:
#       异常处理代码

try:
    1 / 0
except:
    print("出错了")

try:
    1 / 0
except ZeroDivisionError:
    print("出错了")

# TypeError: unsupported operand type(s) for +: 'int' and 'str'
# try:
#     520 + '字符串'
# except ZeroDivisionError:
#     print("出错了")


try:
    1 / 0
except ZeroDivisionError as e:
    print(e)  # division by zero

try:
    1 / 0
    520 + '字符串'
# 可能会出现多个异常，则使用元组的形式包起来
except (ZeroDivisionError, ValueError, TypeError) as e:
    # 忽略跳过
    pass

try:
    1 / 0
    520 + '字符串'
# 也可以单独处理差异
except ZeroDivisionError:
    print("除数不能为0。")
except ValueError:
    print("值不正确。")
except TypeError:
    print("类型不正确。")
